package com.deng.etl.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class ImportBase {

	public static SimpleDateFormat format_s=new SimpleDateFormat("yyyy-MM-dd");
	public static SimpleDateFormat format_l=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	public static int TOPN=2000;
	
	public java.sql.Date getSqlDate(java.util.Date utildate){
		java.sql.Date ret=null;
		ret=new java.sql.Date(utildate.getYear(),utildate.getMonth(),1);
		
		return ret;
		
	}
	
	public static Timestamp getTimestamp(java.util.Date date){

		return Timestamp.valueOf(format_l.format(date));
	}
	
	public void insert(PreparedStatement pst){
		try {
			System.out.println("---------insert-------");
			pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void update(PreparedStatement pst){
		try {
			System.out.println("---------update-------");
			pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public int getStat_id(Connection conn_target ,String org_id){
		int ret=0;
		try {
			Statement st=conn_target.createStatement();
			ResultSet rs=st.executeQuery("select top 1 a.id  from t_sys_stat_department a ,t_sys_stat_department_vs_original_department b " +
					"where b.stat_id=a.id and a.parent_id=1 and b.original_id='"+org_id+"'");
			
			if(rs.next()){
				ret=rs.getInt("id");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ret;
	}
	public String getStat_name(Connection conn_target ,int id){
		String ret=null;
		try {
			Statement st=conn_target.createStatement();
			ResultSet rs=st.executeQuery("select top 1 name from t_sys_stat_department " +
					"where id="+id);
			
			if(rs.next()){
				ret=rs.getString("name");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ret;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
